package ro.ubbcluj.cs.damate.persistence.entities;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import static javax.persistence.CascadeType.ALL;
import static javax.persistence.FetchType.LAZY;
import static javax.persistence.GenerationType.IDENTITY;

/**
 * @author Lóránd Fazakas (lfazakas)
 *         Date: 2013.01.15.
 *         Time: 22:20
 */
@Table(name = "event_parameter", catalog = "damate")
@Entity
public class EventParameter {

    private Long parameterId;

    @Column(name = "parameterId", nullable = false, insertable = true, updatable = true, length = 10, precision = 0)
    @Id
    @GeneratedValue(strategy= IDENTITY)
    public Long getParameterId() {
        return parameterId;
    }

    public void setParameterId(Long parameterId) {
        this.parameterId = parameterId;
    }

    private String paramName;

    @Column(name = "paramName", nullable = false, insertable = true, updatable = true, length = 45, precision = 0)
    @Basic
    public String getParamName() {
        return paramName;
    }

    public void setParamName(String paramName) {
        this.paramName = paramName;
    }

    private String paramValue;

    @Column(name = "paramValue", nullable = true, insertable = true, updatable = true)
    @Basic
    public String getParamValue() {
        return paramValue;
    }

    public void setParamValue(String paramValue) {
        this.paramValue = paramValue;
    }

    private Event event;

    @ManyToOne(fetch = LAZY, cascade = ALL)
    @JoinColumn(name = "event")
    public Event getEvent() {
        return event;
    }

    public void setEvent(Event event) {
        this.event = event;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        EventParameter that = (EventParameter) o;

        if (parameterId != that.parameterId) return false;
        if (paramName != null ? !paramName.equals(that.paramName) : that.paramName != null) return false;
        if (paramValue != null ? !paramValue.equals(that.paramValue) : that.paramValue != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = parameterId.intValue();
        result = 31 * result + (paramName != null ? paramName.hashCode() : 0);
        result = 31 * result + (paramValue != null ? paramValue.hashCode() : 0);
        return result;
    }
}
